import request from './request'

// 获取商品评价列表
export function getProductReviews(productId: number, params?: any) {
  return request({
    url: `/reviews/product/${productId}`,
    method: 'get',
    params
  })
}

// 获取用户评价列表
export function getUserReviews(userId: number, params?: any) {
  return request({
    url: `/reviews/user/${userId}`,
    method: 'get',
    params
  })
}

// 获取商品评价统计信息
export function getReviewStats(productId: number) {
  return request({
    url: `/reviews/product/${productId}/stats`,
    method: 'get'
  })
}

// 检查用户是否已评价商品
export function checkUserReview(productId: number, userId: number) {
  return request({
    url: `/reviews/check/${productId}/${userId}`,
    method: 'get'
  })
}

// 创建评价
export function createReview(data: {
  productId: number
  userId: number
  rating: number
  comment: string
}) {
  return request({
    url: '/reviews',
    method: 'post',
    data
  })
}

// 删除评价
export function deleteReview(reviewId: number, userId: number) {
  return request({
    url: `/reviews/${reviewId}`,
    method: 'delete',
    params: { userId }
  })
} 